<script setup>

import api from './api.js'
import {useRouter} from "vue-router";
import eventbus from "@/utils/eventbus.js";

const router = useRouter();
const {proxy} = getCurrentInstance();

const openFlag = ref(false);

const list = reactive([{
  label: '未盘',
  name: 'draft',
  num: 0,
  color: '#E6A23C'
}, {
  label: '正常',
  name: 'normal',
  num: 0,
  color: '#67C23A'
}, {
  label: '盘亏',
  name: 'loss',
  num: 0,
  color: '#f56C6C'
}, {
  label: '盘盈',
  name: 'profit',
  num: 0,
  color: '#005BF5'
}, {
  label: '待确认',
  name: 'to_confirm',
  num: 0,
  color: '#f56C6C'
}]);

let inventoryId = null;

async function getContent(id) {
  const data = await api.getTipContent(id);
  
  for (const key in data) {
    const one = list.find(item => item.name === key);
    if (!one) {
      continue;
    }
    one.num = data[key];
  }
}

function open(id) {
  getContent(id);
  inventoryId = id;
  openFlag.value = true;
}

function close() {
  openFlag.value = false;
}

function confirm() {

  api.sub(inventoryId).then(data => {

    proxy.$tab.closePage();
    router.push('/asset/assetInventory');
    eventbus.publish('after-inventory');

  })
}

// 外部使用的属性或方法
defineExpose({
  open
})

</script>

<template>
  <div>
    <el-dialog width="300" title="提示" v-model="openFlag" align-center top="50">
      <el-row class="tip-container">
        <el-col v-for="item in list" :span="12">
          <div class="block">
            <label>{{ item.label }}：</label>
            <span :style="{'color': item.color}">{{ item.num }}</span>
          </div>

        </el-col>

      </el-row>

      <div slot="footer">
        <el-row type="flex" justify="end">
          <el-button type="primary" @click="confirm">确定</el-button>
          <el-button @click="close">取 消</el-button>
        </el-row>

      </div>
    </el-dialog>
  </div>
</template>

<style scoped lang="scss">
  .tip-container {
    padding: 15px;
    .block {
      margin-bottom: 10px;
      label {
        width: 60px;
        display: inline-block;
      }
    }
  }


</style>